package com.example.demo.controller;

import com.example.demo.entity.Report;
import com.example.demo.result.Result;
import com.example.demo.service.IReportService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 举报类型表 前端控制器
 * </p>
 *
 * @author Mr.Yang
 * @since 2024-06-01
 */
@Api(tags = "举报类型接口")
@RestController
@RequestMapping("/report")
public class ReportController {

    @Resource
    private IReportService reportService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.Yang")
    @ApiOperation(value = "查询举报类型表所有数据")
    @GetMapping
    public Result<List<Report>> findAll() {
        return Result.success(reportService.findReport()).msg("查询成功");
    }

    /**
     * 根据id查询数据接口
     * @param id
     * @return
     */
    @ApiOperationSupport(author = "Mr.Yang")
    @ApiOperation(value = "根据id查询数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "组件id",required = true)
    })
    @GetMapping("/{id}")
    public Result<Report> findOne(@PathVariable Integer id) {
        if (reportService.findReportById(id) == null) {
            return Result.error().msg("查询失败");
        }
        return Result.success(reportService.findReportById(id)).msg("查询成功");
    }

}